|
1
|
|
|
/*! |
|
2
|
|
|
* @package ElkArte Forum |
|
3
|
|
|
* @copyright ElkArte Forum contributors |
|
4
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
|
5
|
|
|
* |
|
6
|
|
|
* This file contains code covered by: |
|
7
|
|
|
* copyright: 2011 Simple Machines (http://www.simplemachines.org) |
|
8
|
|
|
* |
|
9
|
|
|
* @version 2.0 dev |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This file contains javascript surrounding personal messages send form. |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Personal message Send controller |
|
18
|
|
|
* |
|
19
|
|
|
* sSelf: instance name |
|
20
|
|
|
* sSessionId: |
|
21
|
|
|
* sSessionVar: |
|
22
|
|
|
* sTextDeleteItem: text string to show when |
|
23
|
|
|
* sToControlId: id of the to auto suggest input |
|
24
|
|
|
* aToRecipients: array of members its going to |
|
25
|
|
|
* aBccRecipients: array of member to BCC |
|
26
|
|
|
* sBccControlId: id of the bcc auto suggest input |
|
27
|
|
|
* sBccDivId: container holding the bbc input |
|
28
|
|
|
* sBccDivId2: container holding the bcc chosen name |
|
29
|
|
|
* sBccLinkId: link to show/hide the bcc names |
|
30
|
|
|
* sBccLinkContainerId: container for the above |
|
31
|
|
|
* bBccShowByDefault: boolean to show it on or off |
|
32
|
|
|
* sShowBccLinkTemplate: |
|
33
|
|
|
* |
|
34
|
|
|
* @param {type} oOptions |
|
35
|
|
|
*/ |
|
36
|
|
|
function elk_PersonalMessageSend (oOptions) |
|
37
|
|
|
{ |
|
38
|
|
|
this.opt = oOptions; |
|
39
|
|
|
this.oBccDiv = null; |
|
40
|
|
|
this.oBccDiv2 = null; |
|
41
|
|
|
this.oToAutoSuggest = null; |
|
42
|
|
|
this.oBccAutoSuggest = null; |
|
43
|
|
|
this.init(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// Initialise the PM recipient selection area |
|
47
|
|
|
elk_PersonalMessageSend.prototype.init = function() { |
|
48
|
|
|
if (!this.opt.bBccShowByDefault) |
|
49
|
|
|
{ |
|
50
|
|
|
// Hide the BCC control. |
|
51
|
|
|
this.oBccDiv = document.getElementById(this.opt.sBccDivId); |
|
52
|
|
|
this.oBccDiv.style.display = 'none'; |
|
53
|
|
|
this.oBccDiv2 = document.getElementById(this.opt.sBccDivId2); |
|
54
|
|
|
this.oBccDiv2.style.display = 'none'; |
|
55
|
|
|
|
|
56
|
|
|
// Show the link to bet the BCC control back. |
|
57
|
|
|
let oBccLinkContainer = document.getElementById(this.opt.sBccLinkContainerId); |
|
58
|
|
|
|
|
59
|
|
|
oBccLinkContainer.style.display = 'inline'; |
|
60
|
|
|
oBccLinkContainer.innerHTML = this.opt.sShowBccLinkTemplate; |
|
61
|
|
|
|
|
62
|
|
|
// Make the link show the BCC control. |
|
63
|
|
|
let oBccLink = document.getElementById(this.opt.sBccLinkId); |
|
64
|
|
|
oBccLink.onclick = function() { |
|
65
|
|
|
this.showBcc(); |
|
66
|
|
|
return false; |
|
67
|
|
|
}.bind(this); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
this.oToAutoSuggest = new elk_AutoSuggest({ |
|
|
|
|
|
|
71
|
|
|
sSessionId: this.opt.sSessionId, |
|
72
|
|
|
sSessionVar: this.opt.sSessionVar, |
|
73
|
|
|
sSuggestId: 'to_suggest', |
|
74
|
|
|
sControlId: this.opt.sToControlId, |
|
75
|
|
|
sSearchType: 'member', |
|
76
|
|
|
sPostName: 'recipient_to', |
|
77
|
|
|
sURLMask: 'action=profile;u=%item_id%', |
|
78
|
|
|
sTextDeleteItem: this.opt.sTextDeleteItem, |
|
79
|
|
|
bItemList: true, |
|
80
|
|
|
sItemListContainerId: 'to_item_list_container', |
|
81
|
|
|
aListItems: this.opt.aToRecipients |
|
82
|
|
|
}); |
|
83
|
|
|
this.oToAutoSuggest.registerCallback('onBeforeAddItem', this.callbackAddItem.bind(this)); |
|
84
|
|
|
|
|
85
|
|
|
this.oBccAutoSuggest = new elk_AutoSuggest({ |
|
|
|
|
|
|
86
|
|
|
sSessionId: this.opt.sSessionId, |
|
87
|
|
|
sSessionVar: this.opt.sSessionVar, |
|
88
|
|
|
sSuggestId: 'bcc_suggest', |
|
89
|
|
|
sControlId: this.opt.sBccControlId, |
|
90
|
|
|
sSearchType: 'member', |
|
91
|
|
|
sPostName: 'recipient_bcc', |
|
92
|
|
|
sURLMask: 'action=profile;u=%item_id%', |
|
93
|
|
|
sTextDeleteItem: this.opt.sTextDeleteItem, |
|
94
|
|
|
bItemList: true, |
|
95
|
|
|
sItemListContainerId: 'bcc_item_list_container', |
|
96
|
|
|
aListItems: this.opt.aBccRecipients |
|
97
|
|
|
}); |
|
98
|
|
|
this.oBccAutoSuggest.registerCallback('onBeforeAddItem', this.callbackAddItem.bind(this)); |
|
99
|
|
|
}; |
|
100
|
|
|
|
|
101
|
|
|
// Show the bbc fields |
|
102
|
|
|
elk_PersonalMessageSend.prototype.showBcc = function() { |
|
103
|
|
|
// No longer hide it, show it to the world! |
|
104
|
|
|
this.oBccDiv.style.display = 'block'; |
|
105
|
|
|
this.oBccDiv2.style.display = 'block'; |
|
106
|
|
|
}; |
|
107
|
|
|
|
|
108
|
|
|
// Prevent items to be added twice or to both the 'To' and 'Bcc'. |
|
109
|
|
|
elk_PersonalMessageSend.prototype.callbackAddItem = function(sSuggestId) { |
|
110
|
|
|
this.oToAutoSuggest.deleteAddedItem(sSuggestId); |
|
111
|
|
|
this.oBccAutoSuggest.deleteAddedItem(sSuggestId); |
|
112
|
|
|
|
|
113
|
|
|
return true; |
|
114
|
|
|
}; |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Populate the label selection pulldown after a message is selected |
|
118
|
|
|
*/ |
|
119
|
|
|
function loadLabelChoices () |
|
120
|
|
|
{ |
|
121
|
|
|
var listing = document.forms.pmFolder.elements, |
|
122
|
|
|
theSelect = document.forms.pmFolder.pm_action, |
|
123
|
|
|
toAdd = {length: 0}, |
|
124
|
|
|
toRemove = {length: 0}; |
|
125
|
|
|
|
|
126
|
|
|
if (theSelect.childNodes.length === 0) |
|
127
|
|
|
{ |
|
128
|
|
|
return; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
// This is done this way for internationalization reasons. |
|
132
|
|
|
if (!('-1' in allLabels)) |
|
|
|
|
|
|
133
|
|
|
{ |
|
134
|
|
|
for (let o = 0; o < theSelect.options.length; o++) |
|
135
|
|
|
{ |
|
136
|
|
|
if (theSelect.options[o].value.substring(0, 4) === 'rem_') |
|
137
|
|
|
{ |
|
138
|
|
|
allLabels[theSelect.options[o].value.substring(4)] = theSelect.options[o].text; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
for (let i = 0; i < listing.length; i++) |
|
144
|
|
|
{ |
|
145
|
|
|
if (listing[i].name !== 'pms[]' || !listing[i].checked) |
|
146
|
|
|
{ |
|
147
|
|
|
continue; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
var alreadyThere = [], |
|
151
|
|
|
x; |
|
152
|
|
|
|
|
153
|
|
|
for (x in currentLabels[listing[i].value]) |
|
|
|
|
|
|
154
|
|
|
{ |
|
155
|
|
|
if (!(x in toRemove)) |
|
156
|
|
|
{ |
|
157
|
|
|
toRemove[x] = allLabels[x]; |
|
158
|
|
|
toRemove.length++; |
|
159
|
|
|
} |
|
160
|
|
|
alreadyThere[x] = allLabels[x]; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
for (x in allLabels) |
|
164
|
|
|
{ |
|
165
|
|
|
if (!(x in alreadyThere)) |
|
166
|
|
|
{ |
|
167
|
|
|
toAdd[x] = allLabels[x]; |
|
168
|
|
|
toAdd.length++; |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
while (theSelect.options.length > 2) |
|
174
|
|
|
{ |
|
175
|
|
|
theSelect.options[2] = null; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
if (toAdd.length !== 0) |
|
179
|
|
|
{ |
|
180
|
|
|
theSelect.options[theSelect.options.length] = new Option(txt_pm_msg_label_apply); |
|
|
|
|
|
|
181
|
|
|
theSelect.options[theSelect.options.length - 1].innerHTML = txt_pm_msg_label_apply; |
|
182
|
|
|
theSelect.options[theSelect.options.length - 1].className = 'jump_to_header'; |
|
183
|
|
|
theSelect.options[theSelect.options.length - 1].disabled = true; |
|
184
|
|
|
|
|
185
|
|
|
for (let i in toAdd) |
|
186
|
|
|
{ |
|
187
|
|
|
if (i !== 'length') |
|
188
|
|
|
{ |
|
189
|
|
|
theSelect.options[theSelect.options.length] = new Option(toAdd[i], 'add_' + i); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
if (toRemove.length !== 0) |
|
195
|
|
|
{ |
|
196
|
|
|
theSelect.options[theSelect.options.length] = new Option(txt_pm_msg_label_remove); |
|
|
|
|
|
|
197
|
|
|
theSelect.options[theSelect.options.length - 1].innerHTML = txt_pm_msg_label_remove; |
|
198
|
|
|
theSelect.options[theSelect.options.length - 1].className = 'jump_to_header'; |
|
199
|
|
|
theSelect.options[theSelect.options.length - 1].disabled = true; |
|
200
|
|
|
|
|
201
|
|
|
for (let i in toRemove) |
|
202
|
|
|
{ |
|
203
|
|
|
if (i !== 'length') |
|
204
|
|
|
{ |
|
205
|
|
|
theSelect.options[theSelect.options.length] = new Option(toRemove[i], 'rem_' + i); |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Rebuild the rule description! |
|
213
|
|
|
* @todo: string concatenation is bad for internationalization |
|
214
|
|
|
*/ |
|
215
|
|
|
function rebuildRuleDesc () |
|
216
|
|
|
{ |
|
217
|
|
|
// Start with nothing. |
|
218
|
|
|
var text = '', |
|
219
|
|
|
joinText = '', |
|
220
|
|
|
actionText = '', |
|
221
|
|
|
hadBuddy = false, |
|
222
|
|
|
foundCriteria = false, |
|
223
|
|
|
foundAction = false, |
|
224
|
|
|
curNum, |
|
225
|
|
|
curVal, |
|
226
|
|
|
curDef; |
|
227
|
|
|
|
|
228
|
|
|
// GLOBAL strings, convert to objects |
|
229
|
|
|
/** global: groups */ |
|
230
|
|
|
if (typeof groups === 'string') |
|
|
|
|
|
|
231
|
|
|
{ |
|
232
|
|
|
groups = JSON.parse(groups); |
|
|
|
|
|
|
233
|
|
|
} |
|
234
|
|
|
/** global: labels */ |
|
235
|
|
|
if (typeof labels === 'string') |
|
|
|
|
|
|
236
|
|
|
{ |
|
237
|
|
|
labels = JSON.parse(labels); |
|
|
|
|
|
|
238
|
|
|
} |
|
239
|
|
|
/** global: rules */ |
|
240
|
|
|
if (typeof rules === 'string') |
|
|
|
|
|
|
241
|
|
|
{ |
|
242
|
|
|
rules = JSON.parse(rules); |
|
|
|
|
|
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
for (var i = 0; i < document.forms.addrule.elements.length; i++) |
|
246
|
|
|
{ |
|
247
|
|
|
if (document.forms.addrule.elements[i].id.substr(0, 8) === 'ruletype') |
|
248
|
|
|
{ |
|
249
|
|
|
if (foundCriteria) |
|
250
|
|
|
{ |
|
251
|
|
|
joinText = document.getElementById('logic').value === 'and' ? ' ' + txt_pm_readable_and + ' ' : ' ' + txt_pm_readable_or + ' '; |
|
|
|
|
|
|
252
|
|
|
} |
|
253
|
|
|
else |
|
254
|
|
|
{ |
|
255
|
|
|
joinText = ''; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
foundCriteria = true; |
|
259
|
|
|
|
|
260
|
|
|
curNum = document.forms.addrule.elements[i].id.match(/\d+/); |
|
261
|
|
|
curVal = document.forms.addrule.elements[i].value; |
|
262
|
|
|
|
|
263
|
|
|
if (curVal === 'gid') |
|
264
|
|
|
{ |
|
265
|
|
|
curDef = document.getElementById('ruledefgroup' + curNum).value.php_htmlspecialchars(); |
|
266
|
|
|
} |
|
267
|
|
|
else if (curVal !== 'bud') |
|
268
|
|
|
{ |
|
269
|
|
|
curDef = document.getElementById('ruledef' + curNum).value.php_htmlspecialchars(); |
|
270
|
|
|
} |
|
271
|
|
|
else |
|
272
|
|
|
{ |
|
273
|
|
|
curDef = ''; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
// What type of test is this? |
|
277
|
|
|
if (curVal === 'mid' && curDef) |
|
278
|
|
|
{ |
|
279
|
|
|
text += joinText + txt_pm_readable_member.replace('{MEMBER}', curDef); |
|
|
|
|
|
|
280
|
|
|
} |
|
281
|
|
|
else if (curVal === 'gid' && curDef && groups[curDef]) |
|
|
|
|
|
|
282
|
|
|
{ |
|
283
|
|
|
text += joinText + txt_pm_readable_group.replace('{GROUP}', groups[curDef]); |
|
|
|
|
|
|
284
|
|
|
} |
|
285
|
|
|
else if (curVal === 'sub' && curDef) |
|
286
|
|
|
{ |
|
287
|
|
|
text += joinText + txt_pm_readable_subject.replace('{SUBJECT}', curDef); |
|
|
|
|
|
|
288
|
|
|
} |
|
289
|
|
|
else if (curVal === 'msg' && curDef) |
|
290
|
|
|
{ |
|
291
|
|
|
text += joinText + txt_pm_readable_body.replace('{BODY}', curDef); |
|
|
|
|
|
|
292
|
|
|
} |
|
293
|
|
|
else if (curVal === 'bud' && !hadBuddy) |
|
294
|
|
|
{ |
|
295
|
|
|
text += joinText + txt_pm_readable_buddy; |
|
|
|
|
|
|
296
|
|
|
hadBuddy = true; |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
if (document.forms.addrule.elements[i].id.substr(0, 7) === 'acttype') |
|
301
|
|
|
{ |
|
302
|
|
|
if (foundAction) |
|
303
|
|
|
{ |
|
304
|
|
|
joinText = ' ' + txt_pm_readable_and + ' '; |
|
305
|
|
|
} |
|
306
|
|
|
else |
|
307
|
|
|
{ |
|
308
|
|
|
joinText = ''; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
foundAction = true; |
|
312
|
|
|
|
|
313
|
|
|
curNum = document.forms.addrule.elements[i].id.match(/\d+/); |
|
314
|
|
|
curVal = document.forms.addrule.elements[i].value; |
|
315
|
|
|
|
|
316
|
|
|
if (curVal === 'lab') |
|
317
|
|
|
{ |
|
318
|
|
|
curDef = document.getElementById('labdef' + curNum).value.php_htmlspecialchars(); |
|
319
|
|
|
} |
|
320
|
|
|
else |
|
321
|
|
|
{ |
|
322
|
|
|
curDef = ''; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
// Now pick the actions. |
|
326
|
|
|
if (curVal === 'lab' && curDef && labels[curDef]) |
|
|
|
|
|
|
327
|
|
|
{ |
|
328
|
|
|
actionText += joinText + txt_pm_readable_label.replace('{LABEL}', labels[curDef]); |
|
|
|
|
|
|
329
|
|
|
} |
|
330
|
|
|
else if (curVal === 'del') |
|
331
|
|
|
{ |
|
332
|
|
|
actionText += joinText + txt_pm_readable_delete; |
|
|
|
|
|
|
333
|
|
|
} |
|
334
|
|
|
} |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
// If still nothing make it default! |
|
338
|
|
|
if (text === '' || !foundCriteria) |
|
339
|
|
|
{ |
|
340
|
|
|
text = txt_pm_rule_not_defined; |
|
|
|
|
|
|
341
|
|
|
} |
|
342
|
|
|
else |
|
343
|
|
|
{ |
|
344
|
|
|
if (actionText !== '') |
|
345
|
|
|
{ |
|
346
|
|
|
text += ' ' + txt_pm_readable_then + ' ' + actionText; |
|
|
|
|
|
|
347
|
|
|
} |
|
348
|
|
|
text = txt_pm_readable_start + text + txt_pm_readable_end; |
|
|
|
|
|
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
// Set the actual HTML! |
|
352
|
|
|
document.getElementById('ruletext').innerHTML = text; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* Initializes the update rules actions. |
|
357
|
|
|
* |
|
358
|
|
|
* @returns {void} |
|
359
|
|
|
*/ |
|
360
|
|
|
function initUpdateRulesActions () |
|
361
|
|
|
{ |
|
362
|
|
|
// Maintain the personal message rule options to comply with the rule choice |
|
363
|
|
|
let criteria = document.getElementById('criteria'); |
|
364
|
|
|
criteria.addEventListener('change', function(event) { |
|
365
|
|
|
if (event.target.name.startsWith('ruletype')) |
|
366
|
|
|
{ |
|
367
|
|
|
let optNum = event.target.getAttribute('data-optnum'), |
|
368
|
|
|
selectBox = document.getElementById('ruletype' + optNum); |
|
369
|
|
|
|
|
370
|
|
|
if (selectBox.value === 'gid') |
|
371
|
|
|
{ |
|
372
|
|
|
document.getElementById('defdiv' + optNum).style.display = 'none'; |
|
373
|
|
|
document.getElementById('defseldiv' + optNum).style.display = 'inline'; |
|
374
|
|
|
} |
|
375
|
|
|
else if (selectBox.value === 'bud' || selectBox.value === '') |
|
376
|
|
|
{ |
|
377
|
|
|
document.getElementById('defdiv' + optNum).style.display = 'none'; |
|
378
|
|
|
document.getElementById('defseldiv' + optNum).style.display = 'none'; |
|
379
|
|
|
} |
|
380
|
|
|
else |
|
381
|
|
|
{ |
|
382
|
|
|
document.getElementById('defdiv' + optNum).style.display = 'inline'; |
|
383
|
|
|
document.getElementById('defseldiv' + optNum).style.display = 'none'; |
|
384
|
|
|
} |
|
385
|
|
|
} |
|
386
|
|
|
}); |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* Maintains the personal message rule action options to conform with the action choice |
|
390
|
|
|
* so that the form only makes available the proper choice |
|
391
|
|
|
*/ |
|
392
|
|
|
let actions = document.getElementById('actions'); |
|
393
|
|
|
actions.addEventListener('change', function(e) { |
|
394
|
|
|
let targetEl = e.target, |
|
395
|
|
|
name = targetEl.getAttribute('name'); |
|
396
|
|
|
|
|
397
|
|
|
if (name && name.startsWith('acttype')) |
|
398
|
|
|
{ |
|
399
|
|
|
let optNum = targetEl.getAttribute('data-actnum'); |
|
400
|
|
|
|
|
401
|
|
|
if (document.getElementById('acttype' + optNum).value === 'lab') |
|
402
|
|
|
{ |
|
403
|
|
|
document.getElementById('labdiv' + optNum).style.display = 'inline'; |
|
404
|
|
|
} |
|
405
|
|
|
else |
|
406
|
|
|
{ |
|
407
|
|
|
document.getElementById('labdiv' + optNum).style.display = 'none'; |
|
408
|
|
|
} |
|
409
|
|
|
} |
|
410
|
|
|
}); |
|
411
|
|
|
|
|
412
|
|
|
// Trigger a change on the existing in order to let the function run |
|
413
|
|
|
Array.from(criteria.querySelectorAll('[name^="ruletype"]')).forEach(function(elem) { |
|
414
|
|
|
elem.dispatchEvent(new Event('change')); |
|
|
|
|
|
|
415
|
|
|
}); |
|
416
|
|
|
Array.from(criteria.querySelectorAll('[name^="acttype"]')).forEach(function(elem) { |
|
417
|
|
|
elem.dispatchEvent(new Event('change')); |
|
|
|
|
|
|
418
|
|
|
}); |
|
419
|
|
|
|
|
420
|
|
|
// Make sure the description is rebuilt every time something changes, even on elements not yet existing |
|
421
|
|
|
addMultipleListeners(criteria, 'change keyup', function(e) { |
|
422
|
|
|
let nameAttr = e.target.getAttribute('name'); |
|
423
|
|
|
if ( |
|
424
|
|
|
nameAttr.startsWith('ruletype') || |
|
425
|
|
|
nameAttr.startsWith('ruledefgroup') || |
|
426
|
|
|
nameAttr.startsWith('ruledef') || |
|
427
|
|
|
nameAttr.startsWith('acttype') || |
|
428
|
|
|
nameAttr.startsWith('labdef') || |
|
429
|
|
|
e.target.id === 'logic' |
|
430
|
|
|
) |
|
431
|
|
|
{ |
|
432
|
|
|
rebuildRuleDesc(); |
|
433
|
|
|
} |
|
434
|
|
|
} |
|
435
|
|
|
); |
|
436
|
|
|
|
|
437
|
|
|
// Make sure the description is rebuilt every time something changes, even on elements not yet existing |
|
438
|
|
|
['criteria', 'actions'].forEach(function(id) { |
|
439
|
|
|
let el = document.getElementById(id); |
|
440
|
|
|
addMultipleListeners(el, 'change keyup', function(e) { |
|
441
|
|
|
let nameAttr = e.target.getAttribute('name'); |
|
442
|
|
|
if ( |
|
443
|
|
|
nameAttr.startsWith('ruletype') || |
|
444
|
|
|
nameAttr.startsWith('ruledefgroup') || |
|
445
|
|
|
nameAttr.startsWith('ruledef') || |
|
446
|
|
|
nameAttr.startsWith('acttype') || |
|
447
|
|
|
nameAttr.startsWith('labdef') || |
|
448
|
|
|
e.target.id === 'logic' |
|
449
|
|
|
) |
|
450
|
|
|
{ |
|
451
|
|
|
rebuildRuleDesc(); |
|
452
|
|
|
} |
|
453
|
|
|
} |
|
454
|
|
|
); |
|
455
|
|
|
}); |
|
456
|
|
|
|
|
457
|
|
|
// Rebuild once at the beginning to ensure everything is correct |
|
458
|
|
|
rebuildRuleDesc(); |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
/** |
|
462
|
|
|
* Adds multiple event listeners to an element. |
|
463
|
|
|
* |
|
464
|
|
|
* @param {HTMLElement} element - The element to attach the event listeners to. |
|
465
|
|
|
* @param {string} events - A string containing one or more space-separated event types, e.g., "click mouseover". |
|
466
|
|
|
* @param {Function} handler - The function to be called when the event is triggered. |
|
467
|
|
|
* |
|
468
|
|
|
* @return {void} |
|
469
|
|
|
*/ |
|
470
|
|
|
function addMultipleListeners (element, events, handler) |
|
471
|
|
|
{ |
|
472
|
|
|
events.split(' ').forEach(e => element.addEventListener(e, handler, false)); |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
/** |
|
476
|
|
|
* Add a new rule criteria for PM filtering |
|
477
|
|
|
*/ |
|
478
|
|
|
function addCriteriaOption () |
|
479
|
|
|
{ |
|
480
|
|
|
console.log(criteriaNum); |
|
|
|
|
|
|
481
|
|
|
if (criteriaNum === 0) |
|
482
|
|
|
{ |
|
483
|
|
|
for (let i = 0; i < document.forms.addrule.elements.length; i++) |
|
484
|
|
|
{ |
|
485
|
|
|
if (document.forms.addrule.elements[i].id.substring(0, 8) === 'ruletype') |
|
486
|
|
|
{ |
|
487
|
|
|
criteriaNum++; |
|
|
|
|
|
|
488
|
|
|
} |
|
489
|
|
|
} |
|
490
|
|
|
} |
|
491
|
|
|
criteriaNum++; |
|
492
|
|
|
|
|
493
|
|
|
// Global strings, convert to objects |
|
494
|
|
|
/** global: groups */ |
|
495
|
|
|
if (typeof groups === 'string') |
|
|
|
|
|
|
496
|
|
|
{ |
|
497
|
|
|
groups = JSON.parse(groups); |
|
|
|
|
|
|
498
|
|
|
} |
|
499
|
|
|
/** global: labels */ |
|
500
|
|
|
if (typeof labels === 'string') |
|
|
|
|
|
|
501
|
|
|
{ |
|
502
|
|
|
labels = JSON.parse(labels); |
|
|
|
|
|
|
503
|
|
|
} |
|
504
|
|
|
/** global: rules */ |
|
505
|
|
|
if (typeof rules === 'string') |
|
|
|
|
|
|
506
|
|
|
{ |
|
507
|
|
|
rules = JSON.parse(rules); |
|
|
|
|
|
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
// rules select |
|
511
|
|
|
var rules_option = '', |
|
512
|
|
|
index = ''; |
|
513
|
|
|
|
|
514
|
|
|
for (index in rules) |
|
|
|
|
|
|
515
|
|
|
{ |
|
516
|
|
|
if (rules.hasOwnProperty(index)) |
|
517
|
|
|
{ |
|
518
|
|
|
rules_option += '<option value="' + index + '">' + rules[index] + '</option>'; |
|
519
|
|
|
} |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
// group selections |
|
523
|
|
|
var group_option = ''; |
|
524
|
|
|
|
|
525
|
|
|
for (index in groups) |
|
|
|
|
|
|
526
|
|
|
{ |
|
527
|
|
|
group_option += '<option value="' + index + '">' + groups[index] + '</option>'; |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
|
|
setOuterHTML(document.getElementById('criteriaAddHere'), '<br />' + |
|
531
|
|
|
'<select class="criteria" name="ruletype[' + criteriaNum + ']" id="ruletype' + criteriaNum + '" data-optnum="' + criteriaNum + '">' + |
|
532
|
|
|
' <option value="">' + txt_pm_rule_criteria_pick + ':</option>' + rules_option + '' + |
|
|
|
|
|
|
533
|
|
|
'</select><span class="breaking_space">' + |
|
534
|
|
|
'<span id="defdiv' + criteriaNum + '" class="hide">' + |
|
535
|
|
|
'<input type="text" name="ruledef[' + criteriaNum + ']" id="ruledef' + criteriaNum + '" value="" />' + |
|
536
|
|
|
'</span>' + |
|
537
|
|
|
'<span id="defseldiv' + criteriaNum + '" class="hide">' + |
|
538
|
|
|
'<select class="criteria" name="ruledefgroup[' + criteriaNum + ']" id="ruledefgroup' + criteriaNum + '">' + |
|
539
|
|
|
' <option value="">' + txt_pm_rule_sel_group + '</option>' + group_option + |
|
|
|
|
|
|
540
|
|
|
'</select>' + |
|
541
|
|
|
'</span>' + |
|
542
|
|
|
'<span id="criteriaAddHere"></span>'); |
|
543
|
|
|
|
|
544
|
|
|
return false; |
|
545
|
|
|
} |
|
546
|
|
|
|
|
547
|
|
|
/** |
|
548
|
|
|
* Add a new action for a defined PM rule |
|
549
|
|
|
*/ |
|
550
|
|
|
function addActionOption () |
|
551
|
|
|
{ |
|
552
|
|
|
if (actionNum === 0) |
|
|
|
|
|
|
553
|
|
|
{ |
|
554
|
|
|
for (let i = 0; i < document.forms.addrule.elements.length; i++) |
|
555
|
|
|
{ |
|
556
|
|
|
if (document.forms.addrule.elements[i].id.substr(0, 7) === 'acttype') |
|
557
|
|
|
{ |
|
558
|
|
|
actionNum++; |
|
|
|
|
|
|
559
|
|
|
} |
|
560
|
|
|
} |
|
561
|
|
|
} |
|
562
|
|
|
actionNum++; |
|
563
|
|
|
|
|
564
|
|
|
// Label selections |
|
565
|
|
|
var label_option = '', |
|
566
|
|
|
index = ''; |
|
567
|
|
|
|
|
568
|
|
|
if (typeof labels === 'string') |
|
|
|
|
|
|
569
|
|
|
{ |
|
570
|
|
|
labels = JSON.parse(labels); |
|
|
|
|
|
|
571
|
|
|
} |
|
572
|
|
|
for (index in labels) |
|
|
|
|
|
|
573
|
|
|
{ |
|
574
|
|
|
label_option += '<option value="' + index + '">' + labels[index] + '</option>'; |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
|
setOuterHTML(document.getElementById('actionAddHere'), '<br />' + |
|
578
|
|
|
'<select name="acttype[' + actionNum + ']" id="acttype' + actionNum + '" data-actnum="' + actionNum + '">' + |
|
579
|
|
|
' <option value="">' + txt_pm_rule_sel_action + ':</option>' + |
|
|
|
|
|
|
580
|
|
|
' <option value="lab">' + txt_pm_rule_label + '</option>' + |
|
|
|
|
|
|
581
|
|
|
' <option value="del">' + txt_pm_rule_delete + '</option>' + |
|
|
|
|
|
|
582
|
|
|
'</select><span class="breaking_space">' + |
|
583
|
|
|
'<span id="labdiv' + actionNum + '" class="hide">' + |
|
584
|
|
|
'<select name="labdef[' + actionNum + ']" id="labdef' + actionNum + '">' + |
|
585
|
|
|
' <option value="">' + txt_pm_rule_sel_label + '</option>' + label_option + |
|
|
|
|
|
|
586
|
|
|
'</select></span>' + |
|
587
|
|
|
'<span id="actionAddHere"></span>'); |
|
588
|
|
|
} |
|
589
|
|
|
|